"""
请求日志 | 映射
"""

from mapping.base_mapping import (
    MappingBase,
    get_field_map,
)
from models.po import RequestLogPO
from models.vo import (
    RequestLogDetailVO,
    RequestLogListPage,
    RequestLogListVO,
)
from utils.converter_utils import TimeConverter


class RequestLogMapping(MappingBase):
    """ 请求日志 | 映射 """

    id_field = "request_log_id"
    po = RequestLogPO
    list_vo = RequestLogListVO
    detail_vo = RequestLogDetailVO
    vo_page = RequestLogListPage

    list_mapping = {
        "ip": get_field_map(["request_info", "client", "host"]),
        "method": get_field_map(["route_info", "method"]),
        "path": get_field_map(["route_info", "path"]),
        "path_format": get_field_map(["route_info", "path_format"]),
        "request_time": get_field_map(["time_info", "in_time"], func=TimeConverter.datetime_2_datetime_str),
        "status_code": get_field_map(["response_info", "status_code"]),
        "summary": get_field_map(["route_info", "summary"]),
    }

    detail_mapping = {
        "response_time": get_field_map(["time_info", "out_time"], func=TimeConverter.datetime_2_datetime_str),
        "use_time": get_field_map(["time_info", "total_seconds"]),
    }
